/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cargarDatos;

import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

/**
 *
 * @author civilian
 */
public class SQLIteradorDatos implements IteradorDatos{
    ResultSet rs;
    ConexionBD conexion;
    public SQLIteradorDatos() {
        conexion=new ConexionBD("jdbc:postgresql://localhost:5432/SRA","postgres","postgres");
    }

    SQLIteradorDatos(String nombreTabla, String campos) throws SQLException {
        //TODO: hacer que los argumentos de la conexion sean configurables
        conexion=new ConexionBD("jdbc:postgresql://localhost:5432/SRA","postgres","postgres");
       Statement stmt=conexion.conexion.createStatement(
                                       ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
       rs=stmt.executeQuery(String.format("SELECT * FROM %s",nombreTabla));
    }
    
        SQLIteradorDatos(String select,ConexionBD conexion) throws SQLException {
        this.conexion=conexion;
       Statement stmt=conexion.conexion.createStatement(
                                       ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
       rs=stmt.executeQuery(String.format(select));
//        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public boolean next() throws SQLException{
        return rs.next();
    }

    @Override
    public String getString(int i) throws SQLException {
        return rs.getString(i);
    }

    @Override
    public int getInt(int i) throws SQLException {
        return rs.getInt(i);
    }
    
}
